package com.example.smokealarm.service;

import com.example.smokealarm.model.RpiData;
import com.example.smokealarm.repository.RpiDataRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class RpiDataService {
    @Autowired
    private RpiDataRepository rpiDataRepository;

    public RpiData saveRpiData(RpiData rpiData) {
        return rpiDataRepository.save(rpiData);
    }
    public List<RpiData> getAllRpiData() {
        return rpiDataRepository.findAll();
    }

    public List<RpiData> getRecentData(int hours) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime timeAgo = now.minusHours(hours);
        return rpiDataRepository.findRecentData(timeAgo);
    }

    public List<RpiData> getSmokeData(int hours) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime timeAgo = now.minusHours(hours);
        return rpiDataRepository.findSmokeData(timeAgo);
    }
}